package TCPDemo01;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
    public static void main(String[] args) throws IOException {
        // TCP 协议，接收数据

        //1.创建对象ServerSocket
        ServerSocket ss = new ServerSocket(10000);

        //2、监听客户端的连接
        Socket socket = ss.accept();

        //3、从连接通道中获取输入流读取数据
        InputStream inputStream = socket.getInputStream();
        InputStreamReader reader = new InputStreamReader(inputStream);
        BufferedReader br = new BufferedReader(reader);
        int b;
        while ((b=br.read())!= -1){
            System.out.println((char) b);
        }
        //4、 释放资源
        socket.close();
        inputStream.close();
    }
}
